DRINKLOCATOR ?= {}

DRINKLOCATOR.map ?= {}

DRINKLOCATOR.markLocation ?= (storeWithInventory) ->
    pin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(storeWithInventory.Store.Latitude, storeWithInventory.Store.Longitude));
    DRINKLOCATOR.map.entities.push(pin);

DRINKLOCATOR.getMap ?= (mapCredentials, results, divContainingMap) -> 
    ##alert results
    ##alert results.length
    ##alert results[0]
    ##alert results[0].Store.StoreNumber
    ##alert results[0].Store.Latitude+","+results[0].Store.Longitude
    mapOptions = {
            credentials: mapCredentials,
            height: 480,
            width: 400,
            mapTypeId: Microsoft.Maps.MapTypeId.road,
            zoom: 12
        }
    DRINKLOCATOR.map = new Microsoft.Maps.Map(document.getElementById(divContainingMap), mapOptions);
    
    DRINKLOCATOR.markLocation result for result in results
    DRINKLOCATOR.map.setView({ center: new Microsoft.Maps.Location(results[0].Store.Latitude, results[0].Store.Longitude) });

DRINKLOCATOR.inventorySetup ?= () ->
    $(".storeAddress").click ->
            latitude = $(this).data("latitude")
            longitude = $(this).data("longitude")
            alert("lat: " + latitude + " long: " + longitude)

DRINKLOCATOR.storeSearchSetup ?= (cityTextBoxId, cities) ->
    $("#accordion").accordion({
        collapsible: false
        autoHeight: false})
    $("#TextBoxCity").autocomplete({minLength: 3, source: cities})
    ##alert cityTextBoxId
    ##alert x

DRINKLOCATOR.pageSetupCommon ?= () ->
    $(":button").button()
    $(":submit").button()

DRINKLOCATOR.addPersonalLocationSetup ?= () ->
    $("#accordion").accordion({
        collapsible: false
        autoHeight: false})
